/*
 * 13. Write a program that reads from the console
 * a simple arithmetic expression consisting of
 * one-digit numbers and operations "+" and "-"
 * and calculates its value. For example: The
 * value of the expression "7+3-2+4" is 12.
 */

package _3;

import java.util.Scanner;
import java.util.Stack;

public class _13 {
	public static void main (String[] args) {
		Scanner scn = new Scanner (System.in);
		Stack<Integer> stack = new Stack<Integer> ();
		String operation = null;
		boolean compute = false;

		while (scn.hasNext ()) {
			String s = scn.next ();
			int tmp = 0;

			if (s.compareTo ("=") == 0) {
				break;
			} else if (s.compareTo ("+") == 0 || s.compareTo ("-") == 0) {
				operation = s;
				compute = true;
			} else {
				try {
					tmp = Integer.parseInt (s);
					stack.push (tmp);
				} catch (NumberFormatException e) {
					System.err.println ("error: mismatched input");
					e.printStackTrace ();
					System.exit (1);
				}

				if (compute) {
					if (operation.compareTo ("+") == 0) {
						if (stack.size () < 1) {
							System.err.println ("error: the stack is empty");
							System.exit (1);
						}

						stack.push (stack.pop () + stack.pop ());
					} else if (operation.compareTo ("-") == 0) {
						if (stack.size () < 1) {
							System.err.println ("error: the stack is empty");
							System.exit (1);
						}

						int op2 = stack.pop ();
						stack.push (stack.pop () - op2);
					}
				}

				compute = false;
			}
		}

		if (stack.size () >= 1)
			System.out.println (stack.peek ());
	}
}
